package com.atguigu.gmall;

import jodd.util.ClassUtil;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.util.ClassUtils;

/**
 * @author 李旭
 * @date 2021/11/15 11:31
 * @Description:
 */
public class FastDFSDemo {


    public static void main(String[] args) throws Exception{
        //FastDFSDemo.class.getClassLoader().getResource("").getPath()

        //开始上传文件
        String path = ClassUtils.getDefaultClassLoader().getResource("fdfs_client.conf").getPath();
        //D:\IdeaProjects\gmall-210601\gmall-parent\service\service-product\src\main\resources\fdfs_client.conf
        // init 底层IO流 读取你的指定的文件  IO流不认识相对路径 只绝对路径
        ClientGlobal.init(path);
        //1:上传连接请求
        TrackerClient trackerClient = new TrackerClient();
        //2:连接Tracker
        TrackerServer trackerServer = trackerClient.getConnection();
        //3:StorageClient1 升级版
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,null);
        //4:上传图片   meta:元数据信息  图片的长度是多少  图片是背景  图片描述
        String p = storageClient1.upload_file1("D:\\尚品汇商城\\资料\\图片\\Apple11\\e3284f319e256a5d.jpg",
                "jpg", null);

        System.out.println("http://192.168.200.130:8080/" + p);
        //  http://192.168.200.130:8080/group1/M00/00/00/wKjIgmGR2D2ADD7yAAHG5NpN_9M912.jpg

    }

}
